﻿//#define redis
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebMvc.App.Code
{

    public class Cache
    {
#if redis
        public static ServiceStack.Redis.PooledRedisClientManager clientManager = null;
        public static ServiceStack.Redis.IRedisClient GetRedisClient()
        {
            if (clientManager != null)
            {
                return clientManager.GetClient();
            }
            else
            {
                NFinal.Config.RedisData config = NFinal.Config.ConfigurationManager.RedisConfigs["App"];
                if (config != null)
                {
                    ServiceStack.Redis.RedisClientManagerConfig redisClientManagerConfig = new ServiceStack.Redis.RedisClientManagerConfig();
                    redisClientManagerConfig.AutoStart = config.redisConfigAutoStart;
                    redisClientManagerConfig.MaxReadPoolSize = config.redisConfigMaxReadPoolSize;
                    redisClientManagerConfig.MaxWritePoolSize = config.redisConfigMaxWritePoolSize;
                    Cache.clientManager = new ServiceStack.Redis.PooledRedisClientManager(config.redisReadWriteHosts, config.redisReadOnlyHosts, redisClientManagerConfig);
                    return clientManager.GetClient();
                }
                return null;
            }
        }
#endif
    }
}